package com.test.redis.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.test.redis.entity.ReservationRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 预定记录Mapper
 */
@Mapper
public interface ReservationRecordMapper extends BaseMapper<ReservationRecord> {
    
    /**
     * 查询指定时间段的冲突预定
     */
    @Select("SELECT * FROM reservation_record WHERE room_id = #{roomId} " +
            "AND status = 1 " +
            "AND ((start_time BETWEEN #{startTime} AND #{endTime}) " +
            "OR (end_time BETWEEN #{startTime} AND #{endTime}) " +
            "OR (start_time <= #{startTime} AND end_time >= #{endTime}))")
    List<ReservationRecord> findConflictReservations(@Param("roomId") Long roomId,
                                                     @Param("startTime") LocalDateTime startTime,
                                                     @Param("endTime") LocalDateTime endTime);
}